//
//  LoginViewController.swift
//  GoMro
//
//  Created by mac on 2019/12/3.
//  Copyright © 2019 cn.gomro.app. All rights reserved.
//

import UIKit

/**
 * App 登录
 */
class LoginViewController: BaseViewController {
    
    /** 登录完成 */
    var loginFinishBlock:(()->(Void))?
    
    
    //MARK: - override
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    /** 添加视图 */
    override func addSubViews() {
        self.view.addSubview(self.mainView)
    }
    
    /** 设置导航 */
    override func layoutNavigation() {
        
    }
    
    /** 绑定事件 */
    override func bindViewModel() {
        
        //忘记密码
        self.viewModel.forgetPwdSubject.take(until: self.rac_willDeallocSignal())?.subscribeNext({ (input:Any?) in
            SVProgressHUD.showInfo(withStatus: "忘记密码")
        })
        
        //登录完成
        self.viewModel.loginFinishSubject.take(until: self.rac_willDeallocSignal())?.subscribeNext({[weak self] (input:Any?) in
            guard let self = self else { return }
            
            self.loginFinishBlock?()
        })
    }
    
    override func updateViewConstraints() {
        
        self.mainView.snp.makeConstraints { make in
            make.left.right.top.equalTo(0)
            make.bottom.equalTo(-K_APP_SAFETY_HEIGHT)
        }
        
        super.updateViewConstraints()
    }
    
    
    //MARK: - lazy load
    private lazy var mainView:LoginMainView = {
        let _mv:LoginMainView = LoginMainView.init(ViewModel:self.viewModel)
        return _mv
    }()

    private lazy var viewModel:LoginViewModel = {
        let _vm = LoginViewModel()
        return _vm
    }()
}
